﻿using CRL.Core.Encrypt;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Net.Mime.MediaTypeNames;

namespace CRL.Data
{
    public class CharObfuscate
    {
  
        public static string Convert(string text)
        {
            var data = Encoding.UTF8.GetBytes(text.ToUpper());
            var key = Encoding.UTF8.GetBytes("12vui67plqabcdef");
            var iv = Encoding.UTF8.GetBytes("24535684");
            var result = TripleDES.Encrypt(data, key, iv);
            var str = ConvertByte(result);
            return str.Substring(0, text.Length);
        }
        const string chars2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
        static string ConvertByte(byte[] data)
        {
            var len = chars2.Length;
            var charArray = data.Select(b => chars2[b % len]).ToArray();
            var str = new string(charArray);
            if (System.Text.RegularExpressions.Regex.IsMatch(str, @"^\d"))
            {
                str = "P" + str;
            }
            return str;
        }
    }
}
